﻿namespace PayPal.ButtonManager
{
    using System;
    using com.paypal.sdk.services;
    using com.paypal.sdk.util;

    public static class ButtonManagerHelper
    {
        public static void DeleteButton(string hostedButtonId)
        {
            NVPCallerServices caller = new NVPCallerServices();
            caller.APIProfile = Profile.BMProfile;

            NVPCodec encoder = NameValuePairApiHelper.PrepareEncoder(
                                        method: "BMManageButtonStatus",
                                        hostedButtonId: hostedButtonId,
                                        buttonStatus: "DELETE");

            string response = caller.Call(encoder.Encode());

            NVPCodec decoder = new NVPCodec();
            decoder.Decode(response);

            if (decoder.Get("ACK").Equals("Failure", StringComparison.InvariantCultureIgnoreCase))
            {
                throw new ButtonManagerException(decoder.Get("L_ERRORCODE0"), decoder.Get("L_SHORTMESSAGE0"), decoder.Get("L_LONGMESSAGE0"));
            }
        }
    }
}
